﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiFLEXRegenerateCableCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Flexibles;
using EngineeringInternalExtension;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

[TxPowerEngineeringCommandCategory]
public class CUiFLEXRegenerateCableCmd : TxButtonCommand
{
  private ITxCommandEnabler m_commandEnabler;

  public CUiFLEXRegenerateCableCmd()
  {
    this.m_commandEnabler = (ITxCommandEnabler) new CApSelectedCableEnabler();
  }

  public virtual void Execute(object cmdParams)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    IList<ITxCable> selectedCables = this.GetSelectedCables();
    bool flag1 = false;
    foreach (ITxCable itxCable in (IEnumerable<ITxCable>) selectedCables)
    {
      bool flag2 = true;
      string str = "";
      itxCable.CableData.ControlPointsPositions = new List<TxTransformation>();
      try
      {
        if (TxFlxCableEx.Regenerate(itxCable))
          flag1 = true;
      }
      catch (TxException ex)
      {
        str = CApCableExceptionMessageProvider.ComputeCableExceptionErrorMessage(ex, CApCableExceptionMessageProvider.CableAction.REGENERATION);
        flag2 = false;
      }
      if (!flag2)
      {
        int num = (int) TxMessageBox.ShowModal(str, CApFLEXStringTable.CABLE_REGENERATION_ERROR_DIALOG_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
    }
    if (flag1)
      TxApplication.RefreshDisplay();
    Cursor.Current = current;
  }

  public virtual ITxImage Image => (ITxImage) Images.RegenerateCableCmdIcon;

  private IList<ITxCable> GetSelectedCables()
  {
    IList<ITxCable> selectedCables = (IList<ITxCable>) new List<ITxCable>();
    foreach (ITxObject itxObject in (Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())
    {
      if (itxObject is ITxCable itxCable)
        selectedCables.Add(itxCable);
    }
    return selectedCables;
  }

  public virtual string Category => StringTable.REGENERATE_CABLE_CATEGORY;

  public virtual string Name => StringTable.REGENERATE_CABLE_NAME;

  public virtual string Bitmap => StringTable.REGENERATE_CABLE_BITMAP;

  public virtual string Tooltip => StringTable.REGENERATE_CABLE_TOOLTIP;

  public virtual string Description => StringTable.REGENERATE_CABLE_DESCRIPTION;

  public virtual string LargeBitmap => StringTable.REGENERATE_CABLE_LARGE_BITMAP;

  public virtual ITxCommandEnabler CommandEnabler => this.m_commandEnabler;

  public virtual bool Licensed => true;
}
